How to Write a Case Statement

The case statement in Postgres is really easy to use, let’s take a look to the next example:

select 
	case
		when salary >= 100000 and salary<200000 then '100k'
		when salary >= 200000 then 'more than 200k'
		else 'under_100k'
	end AS salary_level,
case
		when department IN ('human resources','accounting') then 'admin'
		when department IN ('enginering','IT') then 'tech'
		else 'other'
	end AS tasks
from employee;

IN THIS PAGE